Skip to content

fix(particlesys): Add or simplify null-checks to createParticleSystem calls#2724

Merged
xezon merged 4 commits into
TheSuperHackers:mainfrom
stephanmeesters:fix/createparticlesystem-nullcheck
May 20, 2026
Merged

fix(particlesys): Add or simplify null-checks to createParticleSystem calls#2724
xezon merged 4 commits into
TheSuperHackers:mainfrom
stephanmeesters:fix/createparticlesystem-nullcheck

Conversation

@stephanmeesters
Copy link
Copy Markdown

@stephanmeesters stephanmeesters commented May 17, 2026

  • Ensure that the result of createParticleSystem is null checked
  • Remove unnecessary particle template checks when straightforward to do so

Todo

  • Replicate in Generals

@stephanmeesters stephanmeesters marked this pull request as ready for review May 17, 2026 11:14
@stephanmeesters stephanmeesters changed the title fix(particlesys): Add or optimize null-checks to createParticleSystem calls refactor(particlesys): Add or optimize null-checks to createParticleSystem calls May 17, 2026
@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented May 17, 2026

Greptile Summary

This PR simplifies particle system creation guards across ~20 files by removing redundant template null-checks that preceded createParticleSystem calls. The refactoring is valid because ParticleSystemManager::createParticleSystem already has an explicit early-exit guard (if (sysTemplate == nullptr) return nullptr) — confirmed at line 3057-3059 of Core/GameEngine/Source/GameClient/System/ParticleSys.cpp — so checking the returned ParticleSystem* pointer is sufficient.

  • Null-check consolidation: Replaces two-level guards (if (template) { system = create(); if (system) { ... } }) with a single if (system) guard, eliminating ~3–5 lines of boilerplate per call site across both Generals/ and GeneralsMD/ directories.
  • createSlaveSystem in ParticleSys.cpp: Removes the if (m_slaveTemplate) guard before calling createParticleSystem, relying on the same null-safe invariant inside the manager.
  • BeaconClientUpdate.cpp: Collapses the failsafe template null-check into the system-return check — the thread on this file has already flagged it for closer review.

Confidence Score: 5/5

Safe to merge — the refactoring is mechanically correct across all 22 files because createParticleSystem already contains an explicit null-template early return.

The entire PR rests on the invariant that createParticleSystem(nullptr) returns nullptr, which is confirmed in the manager implementation. Every call site that previously guarded with if (template) now calls createParticleSystem unconditionally and checks the returned pointer, producing identical runtime behavior. The BeaconClientUpdate.cpp change has a known subtlety discussed in the thread (senior dev recommends revert), but it does not introduce a crash or data corruption.

BeaconClientUpdate.cpp — its failsafe else branch is now triggered by any null return from createParticleSystem rather than only a missing template name, which the thread has already flagged for review.

Important Files Changed

Filename Overview
Core/GameEngine/Source/GameClient/System/ParticleSys.cpp Removes template null-guard in createSlaveSystem and moves createParticleSystem call before the sys null-check in update; both are safe given the manager's own null-template early return.
Core/GameEngine/Source/GameClient/Drawable/Update/BeaconClientUpdate.cpp Collapses failsafe template null-check into system-return check; semantically broadens the else-fallback condition (already flagged in PR thread, revert recommended by senior dev).
Generals/Code/GameEngine/Source/GameLogic/ScriptEngine/ScriptEngine.cpp Removes outer parentTemp null-guard before createParticleSystem; safe because the manager returns null for null templates and parentSystem is still checked before use.
GeneralsMD/Code/GameEngine/Source/GameLogic/ScriptEngine/ScriptEngine.cpp Identical refactor to Generals counterpart — outer parentTemp guard removed, logic is equivalent.
Generals/Code/GameEngine/Source/GameLogic/Object/Update/StealthDetectorUpdate.cpp Removes outer IRGridParticleSysTmpl guard (unlike GeneralsMD which retains it) and collapses inner double-check; behavior is equivalent in both approaches.
GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/ChinookAIUpdate.cpp Removes template guard and collapses system null-check; logic is correct, though the replacement block introduces slightly inconsistent indentation relative to surrounding code.
Core/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DTankTruckDraw.cpp Template init-if guard replaced with unconditional createParticleSystem call guarded by returned pointer; logically equivalent.
Core/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DTruckDraw.cpp Same pattern as W3DTankTruckDraw — identical refactor, logically equivalent.
Generals/Code/GameEngine/Source/GameLogic/Object/Update/HelicopterSlowDeathUpdate.cpp Removes attachParticleSystem template guard; the particle system attachment and bone positioning logic is correctly preserved under the single sys null-check.
GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/HelicopterSlowDeathUpdate.cpp Identical refactor to Generals counterpart; logic preserved correctly.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    subgraph OLD["Old pattern (removed)"]
        A[findTemplate name] --> B{tmp != null?}
        B -- template found --> C[createParticleSystem tmp]
        B -- null template --> Z[skip, no-op]
        C --> D{system != null?}
        D -- system valid --> E[use system]
        D -- create failed --> Z
    end
    subgraph NEW["New pattern (this PR)"]
        A2[findTemplate name] --> C2[createParticleSystem tmp]
        C2 -- null-safe inside manager --> D2{system != null?}
        D2 -- system valid --> E2[use system]
        D2 -- null template OR create failed --> Z2[skip, no-op]
    end
    subgraph MANAGER["createParticleSystem internals"]
        M1{sysTemplate == null?} -- yes --> M2[return nullptr]
        M1 -- no --> M3[allocate and return system]
    end
Loading

Reviews (5): Last reviewed commit: "Replicate in Generals" | Re-trigger Greptile

Comment thread Core/GameEngine/Source/GameClient/Drawable/Update/BeaconClientUpdate.cpp Outdated
@xezon xezon changed the title refactor(particlesys): Add or optimize null-checks to createParticleSystem calls fix(particlesys): Add or simplify null-checks to createParticleSystem calls May 18, 2026
@xezon xezon added Minor Severity: Minor < Major < Critical < Blocker Gen Relates to Generals ZH Relates to Zero Hour Refactor Edits the code with insignificant behavior changes, is never user facing Fix Is fixing something, but is not user facing labels May 18, 2026
Copy link
Copy Markdown

@xezon xezon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good.

@stephanmeesters
Copy link
Copy Markdown
Author

Replicated: ChinookAIUpdate.cpp and EMPUpdate.cpp don't exist in Generals, LaserUpdate.cpp and StealthDetectorUpdate.cpp diverge a bit.

@xezon
Copy link
Copy Markdown

xezon commented May 20, 2026

Rebase this just to make sure.

@stephanmeesters stephanmeesters force-pushed the fix/createparticlesystem-nullcheck branch from 97bcdd7 to 01d4d86 Compare May 20, 2026 10:36
@stephanmeesters
Copy link
Copy Markdown
Author

Rebase this just to make sure.

Done

@xezon xezon merged commit 7cb3c11 into TheSuperHackers:main May 20, 2026
17 checks passed
@stephanmeesters stephanmeesters deleted the fix/createparticlesystem-nullcheck branch May 20, 2026 11:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Fix Is fixing something, but is not user facing Gen Relates to Generals Minor Severity: Minor < Major < Critical < Blocker Refactor Edits the code with insignificant behavior changes, is never user facing ZH Relates to Zero Hour

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants